package com.example.springboot.controller;

import com.example.springboot.pojo.Base;
import com.example.springboot.pojo.User;
import com.example.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/registry")
    public Base registry(@RequestBody User user,HttpSession session) {
        return userService.registry(user,session);
    }

    @RequestMapping("/sendMail")
    public Base sendMail(@RequestBody Map map, HttpSession session) {
        return userService.send(map,session);
    }

    @RequestMapping("/login")
    public Base login(@RequestBody User user, HttpSession session) {
        return userService.login(user,session);
    }

    @RequestMapping("/findUser")
    public Base findUser(HttpSession session) {
        Object user = session.getAttribute("user");
        if (user !=null) {
            return new Base(null,"ok",1,null);
        }
        return new Base(null,"用户未登录",0,null);
    }
}
